---
sidebar_label: Scheduled Triggers
sidebar_position: 9
description: Manage Scheduled Triggers with the Hasura schema/Metadata API
keywords:
  - hasura
  - docs
  - schema/Metadata API
  - API reference
  - scheduled trigger
---

# Schema/Metadata API Reference: Scheduled Triggers (Deprecated)

:::caution Deprecation

In versions `v2.0.0` and above, the schema/Metadata API is deprecated in
favour of the [schema API](/api-reference/schema-api/index.mdx) and the
[Metadata API](/api-reference/metadata-api/index.mdx).

Though for backwards compatibility, the schema/Metadata APIs will
continue to function.

:::

## Introduction

Scheduled Triggers are used to invoke webhooks based on a timestamp or
cron.

## create_cron_trigger {#schema-metadata-create-cron-trigger}

`create_cron_trigger` is used to create a new cron trigger.

```http
POST /v1/query HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
    "type" : "create_cron_trigger",
    "args" : {
        "name": "sample_cron",
        "webhook": "https://httpbin.org/post",
        "schedule":  "* * * * *",
        "payload": {
            "key1": "value1",
            "key2": "value2"
        },
        "include_in_metadata":false,
        "comment":"sample_cron comment"
    }
}
```

### Args syntax {#schema-metadata-create-cron-trigger-syntax}

| Key                 | Required | Schema                                                                                                                                 | Description                                                                                                                                                                                                     |
| ------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| name                | true     | [TriggerName](/api-reference/syntax-defs.mdx#triggername)                                                                              | Name of the cron trigger                                                                                                                                                                                        |
| webhook             | true     | [WebhookURL](/api-reference/syntax-defs.mdx#webhookurl)                                                                                | URL of the webhook                                                                                                                                                                                              |
| schedule            | true     | Cron Expression                                                                                                                        | Cron expression at which the trigger should be invoked.                                                                                                                                                         |
| payload             | false    | JSON                                                                                                                                   | Any JSON payload which will be sent when the webhook is invoked.                                                                                                                                                |
| headers             | false    | \[[HeaderFromValue](/api-reference/syntax-defs.mdx#headerfromvalue) \|[HeaderFromEnv](/api-reference/syntax-defs.mdx#headerfromenv) \] | List of headers to be sent with the webhook                                                                                                                                                                     |
| retry_conf          | false    | [RetryConfST](/api-reference/syntax-defs.mdx#retryconfst)                                                                              | Retry configuration if scheduled invocation delivery fails                                                                                                                                                      |
| include_in_metadata | true     | Boolean                                                                                                                                | Flag to indicate whether a trigger should be included in the metadata. When a cron trigger is included in the metadata, the user will be able to export it when the Metadata of the graphql-engine is exported. |
| comment             | false    | Text                                                                                                                                   | Custom comment.                                                                                                                                                                                                 |
| replace             | false    | Bool                                                                                                                                   | When replace is set to `true`, the cron trigger will be updated(if exists) and when it's `false` or the field is omitted, then a new cron trigger will be created.                                              |

:::tip Supported from

Scheduled Triggers are supported from versions `v1.3.0` and above.

:::

## delete_cron_trigger {#schema-metadata-delete-cron-trigger}

`delete_cron_trigger` is used to delete an existing cron trigger. The
scheduled events associated with the cron trigger will also be deleted.

```http
POST /v1/query HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
    "type" : "delete_cron_trigger",
    "args" : {
        "name": "sample_cron"
    }
}
```

### Args syntax {#schema-metadata-delete-cron-trigger-syntax}

| Key  | Required | Schema                                                    | Description              |
| ---- | -------- | --------------------------------------------------------- | ------------------------ |
| name | true     | [TriggerName](/api-reference/syntax-defs.mdx#triggername) | Name of the cron trigger |

:::tip Supported from

Scheduled Triggers are supported from versions `v1.3.0` and above.

:::

## create_scheduled_event {#schema-metadata-create-scheduled-event}

`create_scheduled_event` is used to create a scheduled event.

```http
POST /v1/query HTTP/1.1
Content-Type: application/json
X-Hasura-Role: admin

{
    "type" : "create_scheduled_event",
    "args" : {
        "webhook": "https://httpbin.org/post",
        "schedule_at": "2019-09-09T22:00:00Z",
        "payload": {
            "key1": "value1",
            "key2": "value2"
        },
        "headers" : [{
            "name":"header-key",
            "value":"header-value"
        }],
        "comment":"sample scheduled event comment"
    }
}
```

### Args syntax {#schema-metadata-create-scheduled-event-syntax}

| Key         | Required | Schema                                                                                                                                 | Description                                                      |
| ----------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| webhook     | true     | [WebhookURL](/api-reference/syntax-defs.mdx#webhookurl)                                                                                | URL of the webhook                                               |
| schedule_at | true     | Timestamp (ISO8601 format)                                                                                                             | The time at which the invocation should be invoked.              |
| payload     | false    | JSON                                                                                                                                   | Any JSON payload which will be sent when the webhook is invoked. |
| headers     | false    | \[[HeaderFromValue](/api-reference/syntax-defs.mdx#headerfromvalue) \|[HeaderFromEnv](/api-reference/syntax-defs.mdx#headerfromenv) \] | List of headers to be sent with the webhook                      |
| retry_conf  | false    | [RetryConfST](/api-reference/syntax-defs.mdx#retryconfst)                                                                              | Retry configuration if scheduled event delivery fails            |
| comment     | false    | Text                                                                                                                                   | Custom comment.                                                  |

:::tip Supported from

Scheduled Triggers are supported from versions `v1.3.0` and above.

:::
